package com.b1502.store2.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;


import android.widget.TextView;

import com.b1502.store2.R;


import com.b1502.store2.model.bean.OrderBean;

import com.b1502.store2.model.bean.OrderDetailBean2;
import com.b1502.store2.network.StoreParams;
import com.b1502.store2.util.UrlUtil;


import com.google.gson.Gson;


import org.mym.plog.PLog;
import org.xutils.common.Callback;
import org.xutils.x;



import java.text.SimpleDateFormat;


import java.util.Date;

/**
 * 获取订单信息
 */
public class OrderDetailActivity extends BaseActivity {

    private TextView dfk,bh,zj,sh,sj;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        initView();
        String orderId = getIntent().getStringExtra("orderId");
        getOrder("orderId",orderId);
    }

    public void initView(){

         dfk= (TextView) findViewById(R.id.dfk);
         bh= (TextView) findViewById(R.id.bh);
         zj= (TextView) findViewById(R.id.zj);
         sh= (TextView) findViewById(R.id.sh);
         sj= (TextView) findViewById(R.id.sj);

    }

    /**
     * 获取订单
     */
    public void getOrder(String param, String orderId) {
        StoreParams params = new StoreParams(UrlUtil.GetOrder, param, orderId);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onSuccess(String result) {

                OrderDetailBean2 orderDetailBean = new Gson().fromJson(result, OrderDetailBean2.class);
                dfk.setText(orderDetailBean.getStatusText());
                bh.setText(orderDetailBean.getSerial());
                float sum = (float)orderDetailBean.getSum();
                zj.setText("￥"+sum);
                sh.setText(orderDetailBean.getReceiptAddress());
                //获取上一次刷新时间
                SimpleDateFormat dateFormat=new SimpleDateFormat("yyy-MMM-ddd HH:mm");
                Date date=new Date();
                sj.setText(dateFormat.format(date));


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

}
